home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / amiga / cmplibsr.zoo / $asmpass21.P < prev    next >
Text File  |  1988-09-15  |  5KB  |  111 lines

  1. /************************************************************************
  2. *                                    *
  3. * The SB-Prolog System                            *
  4. * Copyright SUNY at Stony Brook, 1986; University of Arizona,1987    *
  5. *                                    *
  6. ************************************************************************/
  7.  
  8. /*-----------------------------------------------------------------
  9. SB-Prolog is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the SB-Prolog General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. SB-Prolog, but only under the conditions described in the
  18. SB-Prolog General Public License.   A copy of this license is
  19. supposed to have been given to you along with SB-Prolog so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies. 
  23. ------------------------------------------------------------------ */
  24. /* **********************************************************************
  25. $asmpass21_export([$asm_syminst/4,$asm_lookup0/3,$asm_lookup/3]).
  26.  
  27. $asmpass21_use($aux1,[_,_,_,_,$umsg/1,_,_,_,_]).
  28. $asmpass21_use($listutil1,[_,_,_,_,_,$nthmember1/3,_,_]).
  29. ********************************************************************** */
  30.  
  31. /*    pass2 takes as input a program containing symbolic labels, 
  32. structure symbols and constants and the symbol tables and returns
  33. a program in which all symbols have been replaced by their byte
  34. code offsets of PSC indices. Also, for "internal" predicates, i.e.
  35. those which are not exported, static linking is carried out as far as
  36. possible.                                */
  37.  
  38. :- mode($asm_syminst,4,[c,d,d,d]).
  39.  
  40. $asm_syminst(getcon(Con,R), getcon(I,R), Csym, Lsym) :-
  41.     $asm_lookup((Con, 0, _), Csym, I). 
  42. $asm_syminst(getstr((Str,Arity), R),getstr(I,R),Csym, Lsym) :-
  43.     $asm_lookup((Str,Arity,_), Csym, I).
  44. $asm_syminst(getstrv((Str,Arity), R),getstrv(I,R),Csym, Lsym) :-
  45.     $asm_lookup((Str,Arity,_), Csym, I).
  46. $asm_syminst(unicon(Con), unicon(I), Csym, Lsym) :-
  47.     $asm_lookup((Con,0,_), Csym, I).
  48. $asm_syminst(putcon(Con,R), putcon(I,R), Csym, Lsym) :-
  49.     $asm_lookup((Con,0,_),  Csym, I).
  50. $asm_syminst(putstr((Str,Arity), R),putstr(I,R),Csym, Lsym) :-
  51.     $asm_lookup((Str,Arity,_), Csym, I).
  52. $asm_syminst(putstrv((Str,Arity), R),putstrv(I,R),Csym, Lsym):-
  53.     $asm_lookup((Str,Arity,_), Csym, I).
  54. $asm_syminst(bldcon(Con),bldcon(I),Csym, Lsym) :- 
  55.     $asm_lookup((Con,0,_), Csym, I).
  56. $asm_syminst(call((Pname, Arity), B), call(I,B), Csym, Lsym) :-
  57.     $asm_lookup((Pname, Arity, _), Csym, I).
  58. $asm_syminst(execute((Pname, Arity)), execute(I), Csym, Lsym) :-
  59.     $asm_lookup((Pname, Arity, _), Csym, I).
  60.  
  61. $asm_syminst(trymeelse(L, A), trymeelse(Val,A), Csym, Lsym) :-
  62.     $asm_lookup((L, Val), Lsym, _).
  63. $asm_syminst(retrymeelse(L, A), retrymeelse(Val,A), Csym, Lsym) :-
  64.     $asm_lookup((L, Val), Lsym, _).
  65. $asm_syminst(try(L, A), try(Val,A), Csym, Lsym) :-
  66.     $asm_lookup((L, Val), Lsym, _).
  67. $asm_syminst(retry(L, A), retry(Val,A), Csym, Lsym) :-
  68.     $asm_lookup((L, Val), Lsym, _).
  69. $asm_syminst(trust(L, A), trust(Val,A), Csym, Lsym) :-
  70.     $asm_lookup((L, Val), Lsym, _).
  71. $asm_syminst(jump(L), jump(Val), Csym, Lsym) :-
  72.     $asm_lookup((L, Val),Lsym,_).
  73. $asm_syminst(jumpz(R, L), jumpz(R,Val), Csym, Lsym) :-
  74.     $asm_lookup((L, Val),Lsym,_).
  75. $asm_syminst(jumpnz(R, L), jumpnz(R,Val), Csym, Lsym) :-
  76.     $asm_lookup((L, Val),Lsym,_).
  77. $asm_syminst(jumplt(R, L), jumplt(R,Val), Csym, Lsym) :-
  78.     $asm_lookup((L, Val),Lsym,_).
  79. $asm_syminst(jumple(R, L), jumple(R,Val), Csym, Lsym) :-
  80.     $asm_lookup((L, Val),Lsym,_).
  81. $asm_syminst(jumpgt(R, L), jumpgt(R,Val), Csym, Lsym) :-
  82.     $asm_lookup((L, Val),Lsym,_).
  83. $asm_syminst(jumpge(R, L), jumpge(R,Val), Csym, Lsym) :-
  84.     $asm_lookup((L, Val),Lsym,_).
  85. $asm_syminst(switchonterm(R, L1, L2), switchonterm(R,Val1,Val2), Csym, Lsym) :-
  86.     $asm_lookup((L1, Val1), Lsym, _),
  87.     $asm_lookup((L2, Val2), Lsym, _).
  88. $asm_syminst(switchonlist(R, L1, L2), switchonlist(R,Val1,Val2), Csym, Lsym) :-
  89.     $asm_lookup((L1, Val1), Lsym, _),
  90.     $asm_lookup((L2, Val2), Lsym, _).
  91. $asm_syminst(Inst,Inst,_,_).
  92.  
  93.  
  94. /*  "$asm_lookup0" is the same as "$asm_lookup", except that it doesn't give
  95.      an error  message if $asm_lookup fails, but simply fails quietly.    */
  96.  
  97. $asm_lookup0( ( abs(Value), Value ), _, _).
  98. $asm_lookup0( Symbol, Symtab, Index ) :- 
  99.     $nthmember1( Symbol, Symtab, Index).
  100.  
  101. $asm_lookup(Symbol,Symtab,Index) :- $asm_lookup0(Symbol,Symtab,Index).
  102. $asm_lookup(Symbol, _, _) :-
  103.     $tell(user),
  104.     $writename('error on lookup in pass2: '),
  105.     $write(Symbol),
  106.     $writename('... aborting execution'),
  107.     $nl,
  108.     abort.
  109.  
  110. /* end asmpass21.P ***************************************************/
  111.